<template>
	<view class="collection">
		<view class="notice" v-if="index==2">
		<uni-notice-bar show-icon scrollable text="提交订单后,3小时内发货,请耐心等待." :speed='50'/>
		</view>
		<uni-popup ref="popup" @change="change" mask-background-color='rgba(0,0,0,0.1)'>
			
			<view class="popup-content">
				<text class="text">成功提交催货单，请耐心等待...</text>
			</view>
		</uni-popup>
		<uni-list>
			<uni-swipe-action v-for="(s,i) in data" :key="i">
				<uni-swipe-action-item>
					<view class="card" >
						<view class="image">
							<image :src="$base+s.pic" mode="widthFix"></image>
						</view>
						<view class="text">
							<text class="title">{{s.title}}</text>
							<text class="price">¥{{s.price}}</text>
							<!-- 已签收 -->
							<text class="time" v-if="index==4">签收时间:{{times}}</text>
							<!-- 待收货 -->
							<button v-if="index==3" @click="receiving(s.oid)">确认收货</button>
							<!-- 代发货 -->
							<button v-if="index==2" @click="urge(s.oid)">催发货</button>
							<!-- 查看订单详情 -->
							<button v-if="index==4" @click="Goodt(s.oid)">查看订单详情</button>

						</view>
					</view>
					<template v-slot:right>
						<view class="right">
							<!-- 收藏 -->
							<text v-if="index==1" @click="scshanchu(s.lid)">删除收藏</text>
							<!-- 已收货和代发货 -->
							<text v-if="index==4" @click="shanchu(s.oid)">删除订单</text>
						</view>
					</template>
				</uni-swipe-action-item>
			</uni-swipe-action>
		</uni-list>

	</view>
</template>

<script>
	import {oredercha,sccha,orderdelete, querensh,scdelete,speedfh,orederxqcha} from '@/service/index.js'
	import {timeTrans} from '@/until/Gettime.js'
	export default {
		name: "collection",
		data() {
			return {
				index: '',
				timout:0,
				data:'',
				dats:'',
				times:''
			};
		},
	 async	onLoad(e) {
		 this.index=e.index
			if(this.index==1){
				
				let  res=await sccha(this.$uid)
				this.data=res.result
			}else{
				
				let  ress=await oredercha(this.$uid,this.index)
				this.data=ress.result
				console.log(this.data[0].deliver_time);
				//转化时间为标准格式
				let fs=timeTrans(this.data[0].deliver_time,1)
				console.log(fs)
				this.times=fs
				
				
			}
		
			
		},
		created() {
			uni.setNavigationBarTitle({
				title: this.index == 1 ? '收藏' : this.index == 2 ? '代发货' : this.index == 3 ? '待收货' : '已签收'
			})
		},
		methods: {
			Goodt(e){
				uni.navigateTo({
					url:'/pages/orderDetails/orderDetails?oid='+e
				})
				
			},
			change(e){
				console.log(e);
			},
			
			async scshanchu(lid){
						let  les=await scdelete(lid)
			if(les.code==200){
					   uni.showToast({
					   	title:'删除成功',
						icon:'success'
					   })
					   
					   
			}
						
						},
			// 点击催发货
		async urge(e) {
				clearTimeout(this.timeout);
				this.timeout = setTimeout(() => {
					this.$refs.popup.open()
					window.location.reload()
				}, 150)
				let abces=await speedfh(this.$uid,e)
				console.log(abces);
				if(abces.code==200){
					
					uni.showToast({
						title:'发货成功'
					})
				}
				
			},
			// 点击确认收货运行
			async receiving(oid){
				let qes=await  querensh(this.$uid,oid)
				if(qes.code==200){
					
					this.$Pagesfresh()
				}
			},
		async shanchu(lid){
			let  les=await orderdelete(lid)
	   if(les.code==200){
		   uni.showToast({
		   	title:'删除成功',
			icon:'success'
		   })
		   
		   
	   }
			
			}
		}
	}
</script>

<style lang="scss">
	.collection .card .text uni-button[data-v-127632e4] {
		right: -29px !important;
	}
	.collection {
		width: 100%;
		.popup-content{
			
			.text{
				color: #a397fd;
				font-weight: bold;
				font-size: 20px;
			}
		}

		.card {
			height: 200rpx;
			padding: 10px;
			// border: 1px solid red;
			background-color: #fff;
			border-radius: 50rpx;
			margin: 5px;
			display: flex;

			.image {
				image {
					width: 200rpx;
				}
			}

			.text {
				width: 60%;
				position: relative;

				text {
					display: block;
				}

				.title {
					width: 100%;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.price {
					color: red;
					font-size: 18px;
					font-weight: bold;
					margin: 30rpx 0 20rpx 0;
				}
				.time{
					font-size: 14px;
				}

				button {
					width: 40%;
					height: 80rpx;
					font-size: 12px;
					line-height: 80rpx;
					position: absolute;
					right: 0;
					bottom: 10rpx;
					background-color: #a397fd;
					color: white
				}
			}
		}

		.right {
			text {
				padding: 0 5rpx;
				width: 150rpx;
				display: block;
				background-color: #cabafd;
				border-radius: 0;
				color: white;
				height: 100%;
				line-height: 230rpx;
				text-align: center;
			}
		}
	}
</style>
